package com.hilinos.base.common.utils;

import com.hilinos.base.user.entity.pojo.UserInfoPoJo;
import com.hilinos.common.common.ReturnCode;
import com.hilinos.common.util.AssertUtils;
import com.hilinos.common.util.ServletUtils;

import org.springframework.stereotype.Component;

@Component
public class ServletRequestUtils {


    public static UserInfoPoJo getUserInfo() {
        Object userInfoObj = ServletUtils.getRequest().getAttribute("userInfo");
        if (userInfoObj instanceof UserInfoPoJo) {
            return (UserInfoPoJo) userInfoObj;
        }
        return null;
    }

    /**
     * 是否是超级管理员
     *
     * @return
     */
    public static boolean isSuperAdmin() {
        UserInfoPoJo userInfo = getUserInfo();
        AssertUtils.isNotEmpty(userInfo, ReturnCode.AUTH_ERROR);
        return "admin".equals(userInfo.getUserType());
    }

}
